package com.anbang.app.ui.frame.fragment

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.appcompat.widget.ListPopupWindow
import androidx.appcompat.widget.PopupMenu
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import com.anbang.app.R
import com.anbang.app.ui.animation.AnimListActivity
import com.anbang.app.ui.animation.MaterialDesignAnimActivity
import com.anbang.app.ui.animation.SVGActivity
import com.anbang.app.ui.frame.study.recycleView.RecycleViewActivity
import com.anbang.app.ui.guide.GuideActivity
import com.anbang.framework.utils.toast
import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.fragment_one_tab.*

/**
 * 功能描述：首页Fragment
 * 创建作者：AnBang
 * 创建时间：2018/6/1
 */
class OneTabFragment : Fragment() {

    private var count = 1

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.fragment_one_tab, container, false)
        count++

        return view
    }

    override fun onStart() {
        super.onStart()
        textView.text = "${textView.text}$count"

        //ListPopupWindow
        listPopupBt.setOnClickListener {
            ListPopupWindow(this.requireContext()).apply {
                //adapter
                setAdapter(ArrayAdapter(this@OneTabFragment.requireContext(),
                        android.R.layout.simple_list_item_1,
                        arrayOf("测试呀1", "测试呀2", "测试呀3", "测试呀4")))
                //设置锚点弹出位置相对锚点位置
                anchorView = it
                //宽高
                height = 500
                width = 500
                setOnItemClickListener { adapterView, view, i, l ->
                    toast("点击了$i")
                    dismiss()
                }
                show()
            }
        }

        popupMeun.setOnClickListener {
            PopupMenu(this.requireContext(), it).apply {
                menuInflater.inflate(R.menu.menu_popup_menu, this.menu)
                show()
            }
        }

        recycleView.setOnClickListener {
            startActivity(Intent(this@OneTabFragment.requireContext(), RecycleViewActivity::class.java))
        }

        guideBt.setOnClickListener {
            startActivity(Intent(this@OneTabFragment.requireContext(), GuideActivity::class.java))
        }

        mdAnimBt.setOnClickListener { startActivity(Intent(this@OneTabFragment.requireContext(), MaterialDesignAnimActivity::class.java)) }

        svgBt.setOnClickListener { startActivity(Intent(this@OneTabFragment.requireContext(), SVGActivity::class.java)) }

        animList.setOnClickListener { startActivity(Intent(this@OneTabFragment.requireContext(), AnimListActivity::class.java)) }
    }
}